﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace Remember
{
    public class Note
    {
        public int ID { get; set; }
        public string Title { get; set; }
        public string Text { get; set; }
        //public DateTime ExpiryDate { get; set; }
        public Date ExpiryDate { get; set; }

        public Note()
        {
            ID = 0;
            Title = "";
            Text = "";
            //ExpiryDate = DateTime.ParseExact(
                //DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss", CultureInfo.CurrentCulture), 
                //"yyyy-MM-ddTHH:mm:ss",
                //CultureInfo.CurrentCulture);
            ExpiryDate = new Date("03-03-2014T12:00:00");
        }

        // returns xml element of itself
        public XElement XML()
        {
            XElement element = new XElement("note",
                new XElement("id", this.ID),
                new XElement("title", this.Title),
                new XElement("text", this.Text),
                new XElement("expirydate", this.ExpiryDate.Value)
                );

            return element;
        }

        public static Note Create(XElement element)
        {
            Note note = new Note();

            note.ID = int.Parse(element.Element("id").Value);
            note.Title = element.Element("title").Value;
            note.Text = element.Element("text").Value;
            //note.ExpiryDate = DateTime.ParseExact(
                //element.Element("expirydate").Value,
                //"yyyy-MM-ddTHH:mm:ss",
                //CultureInfo.CurrentCulture);
            note.ExpiryDate = new Date(element.Element("expirydate").Value);
            return note;
        }
    }
}
